package com.hue.springbootstarter.config;

import com.hue.springbootstarter.properties.HelloProperties;
import com.hue.springbootstarter.service.UserServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类
 */
@Configuration
@EnableConfigurationProperties(value = {HelloProperties.class})
public class HelloAutoConfiguration {
    private final HelloProperties helloProperties;

    public HelloAutoConfiguration(HelloProperties helloProperties) {
        this.helloProperties = helloProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    public UserServiceImpl userService() {
        return new UserServiceImpl(helloProperties.getId(), helloProperties.getName());
    }
}
